package com.jeesite.modules.dataScreen.web;

import com.alibaba.fastjson2.JSON;
import com.jeesite.modules.dataScreen.service.EventOrderProcessService;
import com.jeesite.modules.dataScreen.service.EventOrderService;
import com.jeesite.modules.dataScreen.web.dto.EventOrderDTO;
import com.jeesite.modules.dataScreen.web.dto.EventOrderLogDTO;
import com.jeesite.modules.dataScreen.web.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author machenzhi
 * @date 2024/08/08 10:18
 */
@RestController
@RequestMapping("/exchange/data/accept/api/push")
@Api(tags = "事件推送")
@Slf4j
public class EventOrderApi {

    @Autowired
    private EventOrderService eventOrderService;

    @Autowired
    private EventOrderProcessService eventOrderProcessService;

    @ApiOperation("事件单全量信息推送")
    @PostMapping("/event_sediment")
    public Result<String> pushEvent(@Valid @RequestBody EventOrderDTO dto) {
        try {
            log.info("事件单全量信息推送 dto：{}", JSON.toJSONString(dto));
            eventOrderService.add(dto);
        } catch (Exception e) {
            log.error("事件单全量信息推送失败 dto:{} ==== ,e", dto, e);
            return Result.error(e.getMessage());
        }
        return Result.OK("推送成功");
    }


    @ApiOperation("事件单全量处置环节推送")
    @PostMapping("/event_sediment_log")
    public Result<String> pushEventProcess(@Valid @RequestBody EventOrderLogDTO dto) {
        try {
            log.info("事件单全量处置环节推送 dto：{}", JSON.toJSONString(dto));
            eventOrderProcessService.add(dto);
        } catch (Exception e) {
            log.error("事件单全量处置环节推送 dto:{} ==== ,e", dto, e);
            return Result.error(e.getMessage());
        }
        return Result.OK("推送成功");
    }

}
